<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>修改康复登记计划</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/bootstrap.js" type="text/javascript"></script>
    <script src="js/jsrender.js" type="text/javascript"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            var arrayurl = window.location.search.substring(1).split("&")
            var id = arrayurl[0].split("=")[1]
            // var date = arrayurl[0].split("=")[2]
            $.ajax({
                url: GC.bctx + "recoveryRegister/"+ id,
                type: "GET",
                headers: {"Authorization": localStorage.getItem("token")},
                success:function(r){
                    if(r.successed){
                        $("#recoveryRegisterID").val(r.data.recoveryRegisterID)
                        $("#nurseID").val(r.data.nurseID)
                        $("#nurseName").val(r.data.nurseName)
                        $("#customerID").val(r.data.customerID)
                        $("#customerName").val(r.data.customerName)
                        $("#recoveryRegisterPlan").val(r.data.recoveryRegisterPlan)
                    }else{
                        alert(r.message)
                    }
                }
            })
            $("form").submit(function(){
                if($("#nurseName").val()==""&&$("#customerName").val()==""){
                    alert("请输入正确的护士编号或客户编号")
                    return false;
                }
                $.ajax({
                    url: GC.bctx + "recoveryRegister/update/"+id,
                    type:"PUT",
                    data:$("form").serialize(),
                    headers: {"Authorization": localStorage.getItem("token")},
                    success:function(r){
                        if(r.successed){
                            //修改成功，转向显示所有部门页面
                            alert(r.message)
                            window.location.href="recoveryRegisters.html"
                        }else{
                            //修改失败，显示失败信息
                            alert(r.message)
                        }

                    }
                })
                return false
            })


            $("#nurseID").blur(function(){
                // alert($("#nurseID").val())
                if($("#nurseID").val()==""){
                    $("#nurseName").val("")
                    return false;
                }
                if($("#nurseID").val()!=""){
                    if(isNaN($("#nurseID").val())){
                        alert("护士编号必须为纯数字!")
                        $("#nurseName").val("")
                        return false;
                    }
                    // alert("进入非空")
                    $.ajax({
                        url: GC.bctx + "recoveryRegister/checkNurseID/" + $("#nurseID").val(),
                        type: "GET",
                        headers: {"Authorization": localStorage.getItem("token")},
                        success: function (r) {
                            if (r.successed) {
                                //修改成功，转向显示所有部门页面
                                $("#nurseName").val(r.data)
                            } else {
                                //修改失败，显示失败信息
                                alert(r.message)
                                $("#nurseName").val("")
                            }
                        }
                    })
                }
            })

            $("#customerID").blur(function(){
                if($("#customerID").val()==""){
                    $("#customerName").val("")
                    return false;
                }
                if($("#customerID").val()!=""){
                    if(isNaN($("#customerID").val())){
                        alert("客户编号必须为纯数字!")
                        $("#customerName").val("")
                        return false;
                    }
                    // alert("进入非空")
                    $.ajax({
                        url: GC.bctx + "recoveryRegister/checkCustomerID/" + $("#customerID").val(),
                        type: "GET",
                        headers: {"Authorization": localStorage.getItem("token")},
                        success: function (r) {
                            if (r.successed) {
                                //修改成功，转向显示所有部门页面
                                $("#customerName").val(r.data)
                            } else {
                                //修改失败，显示失败信息
                                alert(r.message)
                                $("#customerName").val("")
                            }
                        }
                    })
                }
            })


        })
    </script>
</head>
<body>
<div class="container-fluid">
    <h1>修改康复登记计划</h1>
    <hr/>
    <form>
        <table>
            <tr class="d-none">
                <td >康复登记编号：</td>
                <td><input id="recoveryRegisterID" name="recoveryRegisterID" type="text" /></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>护士编号：</td>
                <td><input id="nurseID" class="form-control" name="nurseID" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>护士名：</td>
                <td><input id="nurseName" class="form-control" name="nurseName" type="text" readonly="readonly"/></td>
            </tr>
            <tr>
                <td>客户编号：</td>
                <td><input id="customerID" class="form-control" name="customerID" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>客户名：</td>
                <td><input id="customerName" class="form-control" name="customerName" type="text" readonly="readonly"/></td>
            </tr>
            <tr>
                <td>康复计划：</td>
                <td><textarea id="recoveryRegisterPlan" class="form-control" name="recoveryRegisterPlan" type="text" rows="8" cols="30"></textarea></td>
            </tr>
            <tr>
                <td colspan="3" class="text-center">
                    <input type="submit" value="保存"/>
                    <input type="reset" value="重置"/>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>